const http =require("http");
const fs = require("fs");
const list = require("./data");

var newData=[];
var temp;
var n=0;

for(var i=0;i<list.length;i++){
    if(list[i].movieRange!='暂无评分'){
        newData[n]=list[i];
        n++;
    }
}

for(var i=0;i<newData.length;i++){
    for(var j=0;j<newData.length-i-1;j++){
        if(newData[j].movieRange<newData[j+1].movieRange){
            temp=newData[j];
            newData[j]=newData[j+1];
            newData[j+1]=temp;
        }
    }
}

http.createServer((req,res)=>{
    const html = fs.readFileSync("index.html");
    if(req.url=='/'){
        res.setHeader("Content-Type","text/html;charset=utf8");
        res.write(html);
        res.end();
    }
    else if(req.url=='/getlist'){
        res.write(JSON.stringify(newData));
        res.end();
    }
}).listen(8080);
